package com.book.dao.impl;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.book.dao.BookInfoDao;
import com.book.entity.BookInfo;
import com.book.util.HibernateUtil;
@Repository
public class BookInfoDaoImpl  implements BookInfoDao{
	
	@Resource
	private SessionFactory sessionFactory;
	private Session session  ;
	
	@Override
	public BookInfo findById(Integer id) {
		//Session session = HibernateUtil.getSession();
		session = sessionFactory.openSession();
		BookInfo bookInfo = session.get(BookInfo.class,id);
		session.close();
		return bookInfo;
	}

	@Override
	public void saveOrupdate(BookInfo bookInfo) {
		session=sessionFactory.getCurrentSession();
		session.save(bookInfo);
	}
}
